/**
 * @file Types.h
 * @brief 通用类型定义和数据结构
 * @details 定义路径规划中使用的通用数据类型、坐标结构、配置参数等
 */

#ifndef TYPES_H
#define TYPES_H

#include <vector>
#include <cmath>
#include <memory>
#include <unordered_map>
#include <functional>

namespace PathPlanning
{
/**
 * @brief 2D坐标点
 */
struct Point
{
    double x, y;

    Point(double x = 0, double y = 0) : x(x), y(y) {}

    double distanceTo(const Point& other) const
    {
        return std::hypot(x - other.x, y - other.y);
    }

    bool operator==(const Point& other) const
    {
        return std::abs(x - other.x) < 1e-9 && std::abs(y - other.y) < 1e-9;
    }
};

/**
 * @brief 机器人位姿 (位置 + 朝向)
 */
struct Pose
{
    double x, y, theta;

    Pose(double x = 0, double y = 0, double theta = 0) : x(x), y(y), theta(theta) {}

    Point toPoint() const
    {
        return Point(x, y);
    }
};

/**
 * @brief 网格单元坐标
 */
struct GridCell
{
    int x, y;

    GridCell(int x = 0, int y = 0) : x(x), y(y) {}

    bool operator==(const GridCell& other) const
    {
        return x == other.x && y == other.y;
    }
};

/**
 * @brief 网格单元哈希函数
 */
struct GridCellHash
{
    std::size_t operator()(const GridCell& cell) const
    {
        return std::hash<int>()(cell.x) ^ (std::hash<int>()(cell.y) << 1);
    }
};

/**
 * @brief 路径规划结果
 */
struct PlanningResult
{
    bool              success = false;
    std::vector<Pose> path;
    std::vector<Pose> exploredNodes;
    double            pathLength   = 0.0;
    int               iterations   = 0;
    double            planningTime = 0.0;
    std::string       message;
};

/**
 * @brief 算法配置参数基类
 */
struct PlannerConfig
{
    std::string plannerName;
    double      resolution = 0.1; // 地图分辨率 (米/像素)

    virtual ~PlannerConfig() = default;
};

/**
 * @brief 搜索节点基类
 */
struct Node
{
    Point                 position;
    double                gCost = 0.0; // 从起点到当前节点的实际代价
    double                fCost = 0.0; // 总代价 (g + h)
    std::shared_ptr<Node> parent;

    virtual ~Node() = default;
};

} // namespace PathPlanning

#endif